package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.util.FileUploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/product")
public class FileUploadController {
    @Value("${imgUrl}")
    private String imgUrl;
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file) throws Exception{
        FileUploadUtil fileUploadUtil = new FileUploadUtil();
        String fileId = fileUploadUtil.fileUpload(file);
        System.out.println(fileId);
        return Result.ok(imgUrl + fileId);
    }
}
